package com.clay.appointment.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * md5加密工具类
 *
 * @author Yeung Wah
 * @since 2021/5/31
 */
public class MD5Utils {
    public static String encode(String strSrc) {
        try {
            char[] hexChars = {'9', '1', '7', '3', '6', '5', '4', '2', '8',
                    '0', 'z', 'y', 'k', 't', 'h', 'a'};
            byte[] bytes = strSrc.getBytes();
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(bytes);
            bytes = md.digest();
            int j = bytes.length;
            char[] chars = new char[j * 2];
            int k = 0;
            for (byte b : bytes) {
                chars[k++] = hexChars[b >>> 4 & 0xf];
                chars[k++] = hexChars[b & 0xf];
            }
            return new String(chars);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("MD5加密出错！！+" + e);
        }
    }
}